package edu.集合基础.ArrayList;

import edu.集合基础.domain.Student;

import java.util.ArrayList;

public class 案例_集合元素筛选 {
/*需求：定义一个方法，方法接受一个集合对象（泛型为Student）,
* 方法内部将年龄低于18的学生对象找出并存入新集合对象
* 方法返回新集合*/
    public static void main(String[] args) {
        ArrayList<Student> list=new ArrayList<>();


        Student stu1=new Student("张三",20);
        Student stu2=new Student("李四",19);
        Student stu3=new Student("王五",16);
        Student stu4=new Student("赵六",17);
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        list.add(stu4);

        getAge18(list);
    }

    public static void getAge18(ArrayList<Student> list) {
        ArrayList<Student> list1=new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Student stu=list.get(i);
            if (stu.getAge()<18){
                list1.add(stu);
        }

    }
        for (int i = 0; i < list1.size(); i++) {
            Student stu=list1.get(i);
            System.out.println(stu.getName()+",,,"+stu.getAge());
        }
    }
}
